<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>
<style>

</style>

<body>
    <header class="aui-bar aui-bar-nav" style="position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            选择人员
        </div>
        <div class="aui-bar-tab-item" style="float:right;margin:auto 15px auto auto" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan" style="font-size: 1.8rem;"></i>
        </div>
    </header>
    <div style="width:100%;margin-top:70px;"></div>
    <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()">保存</div>

    <div class="aui-content aui-margin-b-15" style="margin-top:20px;">
        <div style="background-color:white;width: 100%;margin-top:2%;margin-bottom:20%; ">
            <table class="table" style='width:100%;font-size: 30px;' id="table">
                <thead>
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 12px;font-weight: bold;">
                        <td algin='center'></td>
                        <td algin='center' style="display: none;">人员编码</td>
                        <td algin='center' style="font-size: 20px;">人员姓名</td>
                    </tr>
                </thead>
                <tbody id="tbodyHtml">
                </tbody>
            </table>

            <div class="aui-list-item-input" style="display: flex;align-items: center; justify-content: flex-start; gap: 8px;">
                <label >维修类型：</label>
                <select id="typeGid" placeholder="请选择">
                </select>
            </div>
        </div>
  
    </div>
   
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var equipCode = ""; //设备编码
    //初始化
    apiready = function() {
            $("#equipCode").focus();
            idSelector = "equipCode";

            $("#locationName").val(api.pageParam.locationName)
            $("#areaName").val(api.pageParam.areaName)
            $("#geographiclocation").val(api.pageParam.geographiclocation)
            doSearch();
            doSearchtypeGid();
        }
        // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }
    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function(ret, err) {
            //alert(ret);扫码的结果都是编码
            //1：设备编码
            if (idSelector == 'equipCode') {

                $("#equipCode").val(ret);
                //查询仓库
                //getWorkCenter(ret, idSelector);
            }
        });
    }

    //维修类型下拉框
    function doSearchtypeGid() {
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                tablename: "md_udi",
                column_name: "code",
                column_value: "name",
                condition: " is_del=0 and udi_type_id = '3ae8e86b59c64c1b916d57c4bc7a1110' ",
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async:false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("typeGid"), html);
                $("#typeGid").val(api.pageParam.type)
            }
        });
    }


    //查询
    function doSearch() {
        //设备编码
        var locationName = $("#locationName").val()
        var areaName = $("#areaName").val()
        var geographiclocation = $("#geographiclocation").val()

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getYdPerson";
        var data = {
            values: {
                sysid : api.pageParam.sysid,
                type:'cx',
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;'>";
                        html += "<td style='width:40px;'><input name='sub' type='checkbox' /></td>";
                        html += "<td name='code' style='display: none;'>" + list[i].code + "</td>";
                        html += "<td name='name' style='font-size: 20px;'>" + list[i].name + "</td>";
                        html += "</tr>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }

    function save(){

        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var person = "";
        var personCode = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            person += (row.find("[name='name']").html() + ',');
            personCode += (row.find("[name='code']").html() + ',');
        });
        if(person.length != 0){
            person = person.substring(0,person.length - 1)
        }
        if(personCode.length != 0){
            personCode = personCode.substring(0,personCode.length - 1)
        }

        if (personCode == null || personCode == "" || personCode == undefined) {
            api.toast({
                msg: "请选择人员后再进行撤销!",
                duration: 3000
            });
            return;
        }
        //设备编码
        var locationName = $("#locationName").val()
        var areaName = $("#areaName").val()
        var geographiclocation = $("#geographiclocation").val()
        var type = $("#typeGid").val()

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getEquipmentFaultCX";
        var data = {
            values: {
                person : person,
                personCode : personCode,
                sysid : api.pageParam.sysid,
                type : type,
                un: un
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';
        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    setPerson();

                //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    //跳转详情页面
    function setPerson() {
        var name = api.pageParam.name;
        api.closeWin();
        api.execScript({
            name: name,
            script: 'doSearch()'
        });
    }


</script>

</html>
